<template>
  <div class="page-cont">
    <van-nav-bar
      :title="typeName + '生产汇总'"
      left-arrow
      @click-left="$router.go(-1)"
    />
    <scroll-list
      v-model="list"
      @onLoad="onLoad"
    >
      <summary-item
        v-for="(item, i) in list"
        :key="i"
        :data="item"
        :type="type"
        @show="showNeamInfo"
      />
    </scroll-list>
  </div>
</template>

<script>
import ScrollList from '@/components/ScrollList/index.vue'
import SummaryItem from './components/SummaryItem.vue'

export default {
  name: "ProduceSummary",
  components: {
    SummaryItem,
    ScrollList
  },
  data() {
    return {
      type: '',
      list: [],
    };
  },
  computed: {
    typeName() {
      return this.type === 'week' ? '周' : this.type === 'month' ? '月' : '年'
    }
  },
  created() {
    this.type = this.$route.params.type
  },
  methods: {
    async onLoad(page, done) {
      // 模拟获取数据
      let res
      if (this.type == 'week') {
        res = await this.api.WEEKLY_PRODUCTION_SUMMARY({ pageNo: page, pageSize: 15 })
        this.list.push(...res.list)
      } else if (this.type == 'month') {
        res = await this.api.MONTHLY_PRODUCTION_SUMMARY({ pageNo: page, pageSize: 15 })
        this.list.push(...res.list)
      } else {
        res = await this.api.ANNUAL_PRODUCTION_SUMMARY({ pageNo: page, pageSize: 15 })
        console.log(res)
        this.list.push(...res.list)
      }

      // 触发加载完成 大于50模拟全部加载完成
      done(res.pageNo === res.totalPage)
    },
    showNeamInfo(data) {
      if (this.type == 'week') {
        this.$router.push({
          path: '/produce/summary/beam/week',
          query: {
            title: data.planningWeek + '梁片信息',
            json: JSON.stringify({
              queryWeekStart: data.weekStartDate + '0000',
              queryWeekEnd: data.weekEndDate + '2359'
            })
          }
        })
      } else if (this.type == 'month') {
        this.$router.push({
          path: '/produce/summary/beam/month',
          query: {
            title: data.year + '梁片信息',
            json: JSON.stringify({
              queryMonth: data.year.replaceAll('-', '').substr(0, 6)
            })
          }
        })
      }
      console.log(data)
    }
  }
};
</script>

<style lang="scss" scoped>
@import "./style.scss";
</style>
